/*
 *  fork_test.c
 *  version 1
 *  Created on: 2010-5-29
 *  Author: wangth
 */
#include <unistd.h>
#include <stdio.h> 
int main () 
{ 
	pid_t fpid; //fpid表示fork函数返回的值
	int count=0;

	printf("beforfork:%d\n", getpid());

	fpid=fork();  //fpid 指向子进程的进程id

	printf("afterfork:%d\n", getpid());
	printf("afterfork fpid is:%d\n", fpid);

	if (fpid < 0) 
		printf("error in fork!"); 
	else if (fpid == 0) {
		printf("i am the child process, my process id is %d\n",getpid());
		count++;
	}
	else {
		printf("i am the parent process, my process id is %d\n",getpid());
		count++;
	}
    
	printf("统计结果是: %d\n",count);
    
	return 0;
}